package org.mainlove.project.web.framework;

import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import org.mainlove.project.web.framework.model.ServiceConfig;

import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.Template;

@SuppressWarnings({ "unchecked", "rawtypes" })
public class ActionDispathGeneration {

	private static final String GEN_PATH = "F:\\java\\workspace\\servlet-demo\\src\\main\\java\\org\\mainlove\\project\\web\\gen\\GenServlet.java";

	public static void main(String[] args) throws Exception {

		String rootPath = ActionDispathGeneration.class.getResource("/").getPath().substring(1);

		ActionRepository.initActionConfigMap(rootPath);
		Map<String, ServiceConfig> map = ActionRepository.getActionConfigMap();

		Map root = new HashMap();
		root.put("g", map);

		Configuration configuration = new Configuration();
		configuration.setObjectWrapper(new DefaultObjectWrapper());

		Template template = configuration.getTemplate("g.ftl");

		Writer out = new OutputStreamWriter(
				new FileOutputStream(
						GEN_PATH),
				"UTF-8");

		template.process(root, out);
	}
}
